﻿using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract.Framework.Services.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;

namespace testlib
{
    public class TransferInfo
    {
        public byte[] from;
        public byte[] to;
        public BigInteger value;

    }
    class FFF
    {
        readonly static byte[] v1= "001122".HexToBytes();
        readonly static BigInteger v2 = "001122".ToBigInteger();
        public static void testStr()
        {
            var tt = "Hello World".AsByteArray();
        }
        public static object test001()
        {
            return v1.Concat(new byte[] { 0xaa,0xbb });
        }
        public static object test002()
        {
            return v2;
        }
        public static bool teststr()
        {
            var s1 = "fuck";

            return s1 == "fuck";
        }
        public static bool teststr1()
        {
            var s1 = "fuck2";

            return s1 == "fuck";
        }
        public static bool teststr2()
        {
            var s1 = "fuck";
            return s1 != "fuck";
        }
        public static bool teststr3()
        {
            var s1 = "fuck2";
            return s1 != "fuck";
        }
        static readonly string aabc = "fuck";
        public static string OtherString()
        {
            return FFF.aabc;
        }
        const ulong abb = 255;
        const long abc = 255;
        private const ulong factor = 100000000;
        private static readonly BigInteger total_amount = 100000000000 * factor;
        public static bool IsPayable(byte[] p1)
        {
            var c = Blockchain.GetContract(p1);
            if (c == null)
                return true;
            return c.IsPayable;
        }
        public static ulong testnum()
        {
            return factor;
        }
        public static ulong testnum_call()
        {
            testnum();
            return 3;

        }
        public static ulong testnum_acall()
        {
            FFF.acall();
            return 3;

        }

        public static bool testMapbug()
        {
            int x = 10;
            if (x == 0)
                return false;
            // < ----------- put anything here and it will work!   It can be a random initialization, function call... anything.
            Map<string, int> m = new Map<string, int>();
            return true;
        }

        public delegate int dcall();
        public static ulong testnum_dacall()
        {
            dcall call = (dcall)new byte[] { 01, 02, 03 }.ToDelegate();
            call();
            return 3;
        }
        public static BigInteger testnum2()
        {
            return total_amount;
        }
        public static BigInteger testnum3()
        {
            return total_amount;
        }
        public static byte[] TestDoubleZero(byte[] from, byte[] to, BigInteger value)
        {
            TransferInfo info = new TransferInfo();
            info.from = from;
            info.to = to;
            info.value = value;

            //用一个老式实现法
            var doublezero = new byte[2] { 0, 0 };

            //优化的拼包方法

            var data = info.from;
            var lendata = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2);
            ////lendata是数据长度得bytearray，因为bigint长度不固定，统一加两个零，然后只取前面两个字节
            ////为什么要两个字节，因为bigint是含有符号位得，统一加个零安全，要不然长度129取一个字节就是负数了
            var txinfo = lendata.Concat(data);

            data = info.to;
            lendata = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2);
            txinfo = txinfo.Concat(lendata).Concat(data);

            data = value.AsByteArray();
            lendata = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2);
            txinfo = txinfo.Concat(lendata).Concat(data);

            return txinfo;

        }
        public static byte[] TestDoubleZero1(int v)
        {
            var doublezero = new byte[] { 0, 0 };
            var dlen = ((BigInteger)v).ToByteArray().Concat(doublezero).Range(0, 2);
            return doublezero;
        }
        static readonly byte[] _doublezero = new byte[] { 0, 0 };
        public static byte[] TestDoubleZero2()
        {
            return _doublezero;
        }
        [Appcall(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 })]
        public extern static int acall();

        [OpCode(Neo.VM.OpCode.LEFT)]
        public extern static byte[] Take(byte[] good, int index);
    }
    public class StorageContextEx : StorageContext
    {
        public byte[] this[byte[] key]
        {
            get
            {
                return Storage.Get(this, key);
            }
            set
            {
                Storage.Put(this, key, value);
            }
        }
    }

    public enum cool : byte
    {
        c1,
        c2,
    }
    public class StorageMap
    {
        internal StorageContext Context;
        internal string Prefix;
    }

    public static class HelperS
    {
        public static StorageMap CreateMap(this StorageContext context, string prefix)
        {
            return new StorageMap
            {
                Context = context,
                Prefix = prefix
            };
        }

        public static void Delete(this StorageMap map, byte[] key)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key);
            Storage.Delete(map.Context, k);
        }

        public static void Delete(this StorageMap map, string key)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key.AsByteArray());
            Storage.Delete(map.Context, k);
        }

        public static byte[] Get(this StorageMap map, byte[] key)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key);
            return Storage.Get(map.Context, k);
        }

        public static byte[] Get(this StorageMap map, string key)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key.AsByteArray());
            return Storage.Get(map.Context, k);
        }

        public static void Put(this StorageMap map, byte[] key, byte[] value)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key);
            Storage.Put(map.Context, k, value);
        }

        public static void Put(this StorageMap map, byte[] key, BigInteger value)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key);
            Storage.Put(map.Context, k, value);
        }

        public static void Put(this StorageMap map, byte[] key, string value)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key);
            Storage.Put(map.Context, k, value);
        }

        public static void Put(this StorageMap map, string key, byte[] value)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key.AsByteArray());
            Storage.Put(map.Context, k, value);
        }

        public static void Put(this StorageMap map, string key, BigInteger value)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key.AsByteArray());
            Storage.Put(map.Context, k, value);
        }

        public static void Put(this StorageMap map, string key, string value)
        {
            byte[] k = map.Prefix.AsByteArray().Concat(new byte[] { 0 }).Concat(key.AsByteArray());
            Storage.Put(map.Context, k, value);
        }
    }

    public class info
    {
        public byte[] a;
        public byte[] b;
    }

    public class TestClass : SmartContract
    {
        private const ulong total_ico_usd = 1200;
        private const ulong neo_to_usd = 40;
        private const ulong neo_decimals = 100000000;
        private const ulong total_neo = total_ico_usd / neo_to_usd * neo_decimals;
        public static BigInteger TotalIcoNeo() => total_neo;



        public static Map<string, byte[]> Test_Map2()
        {
            var map = new Map<string, byte[]>();
            map["abc"] = new byte[] { 0 };
            map.Remove("abc");
            return map;
        }


        public static byte[] Test_Serialize()
        {
            var v = new object[2];
            v[0] = new byte[] { 0, 1, 2 };
            v[1] = new byte[] { 3, 3, 2 };

            byte[] abb = Neo.SmartContract.Framework.Helper.Serialize(v);
            return abb;
        }
        public static object[] Test_DeSerialize()
        {
            var data = Test_Serialize();
            return (object[])Neo.SmartContract.Framework.Helper.Deserialize(data);
        }
        public static byte[] Test_Serialize2()
        {
            var v = new object[2];
            v[0] = new byte[] { 0, 1, 2 };
            v[1] = new byte[] { 3, 3, 2 };

            byte[] abb = v.Serialize();
            return abb;
        }
        public static object[] Test_DeSerialize2()
        {
            var data = Test_Serialize();
            return (object[])data.Deserialize();
        }

        public static byte[] Test_Serialize3()
        {
            var v = new info();
            v.a = new byte[] { 0, 1, 2 };
            v.b = new byte[] { 3, 3, 2 };

            byte[] abb = v.Serialize();
            return abb;
        }
        public static info Test_DeSerialize3()
        {
            var data = Test_Serialize();
            return (info)(object)data.Deserialize();
        }


        public static object NotGood()
        {
            byte[] form = new byte[1];
            if (Runtime.CheckWitness(form))
            {
                return new byte[] { 0 };


            }
            return new byte[] { 1 };
        }
        public static object splitStorage(byte[] arg)
        {
            StorageMap account = Storage.CurrentContext.CreateMap(nameof(account));
            byte[] old = account.Get("user1");
            account.Put("user1", arg);
            return old;
        }
        public static object linkErr(byte[] signature)
        {

            Header header = Blockchain.GetHeader(Blockchain.GetHeight());
            if (header.Timestamp < 1513809300)
                return false;
            else
                return VerifySignature(new byte[] { 2, 133, 234, 182, 95, 74, 1, 38, 228, 184, 91, 78, 93, 139, 126, 48, 58, 255, 126, 251, 54, 13, 89, 95, 46, 49, 137, 187, 144, 72, 122, 213, 170 }, signature);
        }
        public static bool linkErr2(byte[] signature, int a)
        {
            Header header = Blockchain.GetHeader(Blockchain.GetHeight());
            if (header.Timestamp < 1499328600) // 2017-6-6 18:10
                return false;
            // Paste the public key byte array here
            return VerifySignature(new byte[] { 2, 133, 234, 182, 95, 74, 1, 38, 228, 184, 91, 78, 93, 139, 126, 48, 58, 255, 126, 251, 54, 13, 89, 95, 46, 49, 137, 187, 144, 72, 122, 213, 170 }, signature);
        }
        //public readonly static byte[] address = Helper.AddressString2ScriptHashBytes("ALjSnMZidJqd18iQaoCgFun6iqWRm2cVtj");
        //public readonly static byte[] data = Helper.HexString2Bytes("a1b1a2b2");

        //public static byte[] store_0()
        //{
        //    Runtime.Notify(address, data);
        //    return data;
        //}
        public static byte[] store_1()
        {
            var c = Storage.CurrentContext;
            Storage.Put(c, new byte[] { 01, 02 }, new byte[] { 03, 04 });
            return Storage.Get(c, new byte[] { 01, 02 });
        }
        //public static byte[] store_2()
        //{
        //    var c = Storage.CurrentContext;
        //    c[new byte[] { 01, 02 }] = new byte[] { 03, 04 };
        //    return c[new byte[] { 01, 02 }];
        //}
        public static object VVT_Main()
        {
            Block block0 = Blockchain.GetBlock(0);
            Transaction tx0 = block0.GetTransaction(0);
            return tx0;
        }
        public static bool VVT2_Main()
        {
            byte[] key = "Hello".AsByteArray();
            Storage.Delete(Storage.CurrentContext, key);
            byte[] value = Storage.Get(Storage.CurrentContext, key);
            if (value.Length != 0)
            {
                return false;
            }
            value = "World".AsByteArray();
            Storage.Put(Storage.CurrentContext, key, value);
            if (Storage.Get(Storage.CurrentContext, key) != value)
            {
                return false;
            }
            value = "Hello".AsByteArray();
            if (Storage.Get(Storage.CurrentContext, key) != value)
            {
                return false;
            }
            Storage.Delete(Storage.CurrentContext, key);
            if (value.Length != 0)
            {
                return false;
            }
            return true;
        }
        public static object VVT3_Main()
        {
            byte[] programHash = { 156, 200, 116, 173, 138, 132, 16, 251, 229, 247, 170, 139, 222, 197, 89, 178, 83, 47, 112, 255 };
            Account account = Blockchain.GetAccount(programHash);
            byte[] assetid = { 155, 124, 255, 218, 166, 116, 190, 174, 15, 147, 14, 190, 96, 133, 175, 144, 147, 229, 254, 86, 179, 74, 92, 34, 12, 205, 207, 110, 252, 51, 111, 197 };
            long balance = account.GetBalance(assetid);
            return account;
        }

        //传入一个参数，实际上传byte[] ,将这个byte作为脚本hash，动态调用
        public static bool Verify06_2(Action<string, string> call)
        {
            call("bb", "cc");
            return true;
        }
        public static bool Verify06(acall call)
        {
            call("bb");
            return true;
        }
        public static bool Verify07()
        {
            //将一个byte[] 转换为delegate，然后就作为 scripthash,动态调用
            acall call = (acall)new byte[] { 01, 02, 03 }.ToDelegate();
            call("cc");
            return true;
        }
        public static void Test_WMI()
        {
            Main_WMI(new byte[] { 123, 1, 2 }, new byte[] { 1, 2 }, "cool day");
        }
        public static void Main_WMI(byte[] sign, byte[] pubkey, string text)
        {
            var magicstr = "who am i2.";//魔法数据，就算别人也写了一样的合约，我还是可以有我独特的版本

            if (SmartContract.VerifySignature(sign, pubkey) == false)
            {
                Runtime.Log("verify fail");//调试用
                return;
            }
            Runtime.Log("verify succ");//调试用

            //用pubkey 计算出scripthash，因为地址是scripthash处理了一下
            //scripthash 和用户地址可以互相转换
            byte[] head = { 33 };
            byte[] end = { 0xac };
            byte[] script = Neo.SmartContract.Framework.Helper.Concat(head, pubkey);
            script = Neo.SmartContract.Framework.Helper.Concat(script, end);
            Runtime.Notify(script);//调试用
            byte[] scriphash = SmartContract.Hash160(script);

            Runtime.Notify(scriphash);//调试用

            //用Scripthash做key，别人用scripthash就可以查了
            Storage.Put(Storage.CurrentContext, scriphash, text);
            Runtime.Log("set succ");//调试用
        }
        public static object test_take()
        {
            byte[] bytes = { 1, 2, 3, 4, 5, 6 };
            return FFF.Take(bytes, 2);
        }
        public static object Main222_t()
        {
            return Main222("totalIcoNeo", null);
        }
        public static object Main222(string operation, params object[] args)
        {
            if (operation == "totalIcoNeo")
            {
                return TotalIcoNeo();
            }
            else
            {
                operation = "abc";

                return operation;
            }
        }

        [Appcall("97b9373228d508155d5bdf75cd4703dfb1137fe0")]
        public static extern bool AnotherContract(string arg, object[] args);
        public static bool Main22()
        {
            return AnotherContract("deploy", new object[0]);
        }
        [Appcall("010203040506070809AA010203040506070809AA")]//hash
        public static extern bool AnotherContract2(int arg1);

        public delegate void acall(string a);
        public static event acall dodododo;
        [System.ComponentModel.DisplayName("dodo2")]
        public static event acall dododo;

        public static string Name() => "ddd";
        public static readonly byte[] abc = { 1, 2, 3 };
        [System.ComponentModel.DisplayName("dodododo2")]
        public static bool Verify05(cool a)
        {
            var c = Name();
            dododo("hello");
            throw new System.FormatException("fuck");

            return true;
        }

        public static byte[] Test_abc()
        {
            return abc;
        }
        public static int Main_AAA(int a)
        {
            return ++a;
        }
        public static object Main04()
        {
            short[] some = new short[17];
            some[1] = 12;
            return some;

        }

        public static int test00(byte[] a, byte[] b, int c)
        {
            return FFF.acall();
        }
        public static int test01()
        {
            int k = 100;
            for (int j = 0; j < 3; j++)
            {
                k += j;
            }
            return k;

        }
        public static int test02()
        {
            int k = 100;
            for (int j = 0; j < 10; j++)
            {
                if (j % 2 == 0)
                    k += j;
            }
            return k;

        }

        public static int test03()
        {
            var i = 5;
            int k = 100;
            //for (int j = i; j < 1; j++)
            {
                k += 3;
            }
            return k;

        }
        public static int testBignumber_01()
        {
            ulong total_neo = 200;
            BigInteger ico_neo = 300;
            BigInteger balance_neo = total_neo - ico_neo;
            ulong value = 150;
            if (balance_neo < 0)
            {
                return 1;
            }
            else if (balance_neo <= value)
            {
                return 2;
            }
            else
            {
                return 3;
            }
        }
        public static int testBignumber_04(BigInteger abc)
        {
            var a1 = abc + 1;
            var a2 = abc - 1;
            var a3 = abc * 1;
            var a4 = abc / 1;
            var a5 = abc % 2;
            if (a1 > 1) ;
            if (a1 >= 2) ;
            if (a1 < 3)
                return 1;
            if (a1 <= 3) ;
            if (a1 > a2) ;
            if (a2 < a3) ;
            if (a3 == a2) ;
            if (a3 != a2) ;
            if (a1 >= a2) ;
            if (a1 <= a2) ;

            return (int)(abc) * 10;
        }

        //单一入口点
        [System.ComponentModel.DisplayName("__main")]
        public static bool Main()
        {
            //var i = 10;
            var a = new byte[] { 1, 1, 1, 1 };
            var b = new byte[] { 2, 2, 2, 2 };
            //foreach(var dc in a)
            //{

            //}
            var i = test00(a, b, 4);//轉換為call

            var c = VerifySignature(a, b);//轉換為指令
            //var hash = ExecutionEngine.CallingScriptHash;//轉換為syscall

            testBignumber_04(3);//轉換為call
            return c;
            //BigInteger bb = 3;
            //var j = testBignumber_04(bb);
            //return j;
        }

        ////特定入口点
        //[EntryPoint(TriggerType.Application)]
        //[System.ComponentModel.DisplayName("main")]
        //public static bool SpMain()
        //{
        //    return true;
        //}
        //[EntryPoint(TriggerType.ApplicationR)]
        //public static bool SPMain2(int a1,int a2)
        //{
        //    return false;
        //}
        public static int TPool(uint timestamp, byte[] pubkey, byte[] signature)
        {
            Block block = Blockchain.GetBlock(Blockchain.GetHeight());
            var t = block.GetTransaction(0);
            //Block block  = Blockchain.GetBlock("abcde");
            //if (timestamp > block.Timestamp) return 3;
            //var b = VerifySignature(signature, pubkey);
            //if (b) return 2;
            //else
            return 1;
        }
        public static object unittest_001()
        {
            TransactionInput[] references = ((Transaction)ExecutionEngine.ScriptContainer).GetInputs();
            var i = 0;
            foreach (TransactionInput reference in references)
            {
                var hash = reference.PrevHash;
                var id = reference.PrevIndex;
                i += id;
            }
            //var hash2 = ExecutionEngine.CallingScriptHash;
            return i;
        }
        public static int unittest_002()
        {
            var a = new byte[] { 1, 1, 1, 1 };
            //foreach (var dc in a)
            //{

            //}
            return 3;
        }
        public static void add(int i1, int i2, int i3, int i4, int i5, int i6, int i7)
        {

        }
        public static byte[] unittest_array_01()
        {
            var bb = new byte[] { 123, 2, 1, 3 };
            return bb;
        }
        public static byte[] unittest_array01()
        {
            return new byte[] { 1 };
        }
        public static byte[] unittest_array02()
        {
            return new byte[] { 213, 1 };
        }
        public static byte[] unittest_array03()
        {
            return new byte[] { 2, 1, 3 };
        }
        public static object unittest_003()
        {
            string ss3 = "ab";
            ss3 += "c";
            var b = TPool(345, new byte[] { 123, 2, 1, 3 }, new byte[] { 2, 2, 3 });

            var bb = new byte[] { 123, 2, 1, 3 };
            var ss = "abcdef";
            var b1 = bb.Length;
            var b2 = ss.Length;

            var c = ss + "abc";
            var d = ss.Substring(1, 2);
            //var e = ss.Substring(2);

            return ss;

        }
        public static int unittest_004()
        {
            add(1, 2, 3, 4, 5, 6, 7);
            return 2;

        }
        //public static int Main_Switch(int di)
        //{
        //    int i = 4;
        //    switch (i)
        //    {
        //        case 1:
        //            i += 4;
        //            break;
        //        case 2:
        //            i += 24;
        //            break;
        //        case 3:
        //            i += 34;
        //            break;
        //        case 4:
        //            i += 44;
        //            break;
        //        case 53333333:
        //            i += 54;
        //            break;
        //        case 6:
        //            i += 64;
        //            break;
        //        case 75555:
        //            i += 74;
        //            break;
        //        default:
        //            i += 1;
        //            break;
        //    }
        //    return i;
        //}
        //public static object Main_Domain_1()
        //{
        //    return Main_Domain("delete");
        //}

        //public static object Main_Domain(string operation, params object[] args)
        //{

        //    switch (operation)
        //    {
        //        case "query":
        //            return Query((string)args[0]);
        //        case "register":
        //            return Register((string)args[0], (byte[])args[1], (byte[])args[2]);
        //        case "transfer":
        //            return Transfer((string)args[0], (byte[])args[1], (byte[])args[2], (byte[])args[2]);
        //        case "delete":
        //            return 44;// Delete((string)args[0], (byte[])args[1]);
        //        case "11":
        //            return Query((string)args[0]);
        //        case "22":
        //            return Query((string)args[0]);
        //        case "33":
        //            return Query((string)args[0]);
        //        case "44":
        //            return Query((string)args[0]);
        //        case "55":
        //            return Query((string)args[0]);
        //        case "77":
        //            return Query((string)args[0]);
        //        default:
        //            return 333;
        //    }
        //}

        private static byte[] Query(string domain)
        {
            return Storage.Get(Storage.CurrentContext, domain);
        }

        private static bool Register(string domain, byte[] owner, byte[] signature)
        {
            if (!VerifySignature(owner, signature)) return false;
            byte[] value = Storage.Get(Storage.CurrentContext, domain);
            if (value != null) return false;
            Storage.Put(Storage.CurrentContext, domain, owner);
            return true;
        }

        private static bool Transfer(string domain, byte[] signature_from, byte[] to, byte[] signature_to)
        {
            if (!VerifySignature(to, signature_to)) return false;
            byte[] from = Storage.Get(Storage.CurrentContext, domain);
            if (from == null) return false;
            if (!VerifySignature(from, signature_from)) return false;
            Storage.Put(Storage.CurrentContext, domain, to);
            return true;
        }

        private static bool Delete(string domain, byte[] signature)
        {
            byte[] owner = Storage.Get(Storage.CurrentContext, domain);
            if (owner == null) return false;
            if (!VerifySignature(owner, signature)) return false;
            Storage.Delete(Storage.CurrentContext, domain);
            return true;
        }
        public struct testS
        {
            public int a;
            public string b;
            public byte[] c;
        }

        public static int testStruct()
        {
            testS s = new testS();
            s.a = 55;
            return s.a;
        }
        public struct Point
        {
            public int x;
            public int y;

            public void Add(Point b)
            {
                this.x += b.x;
                this.y += b.y;
            }
            public static Point SAdd(Point a, Point b)
            {
                Point p = new Point { x = a.x + b.x, y = a.y + b.y };
                return p;
            }
            public static Point Clone(Point src)
            {
                Point p = new Point { x = src.x, y = src.y };
                return p;
            }
        }
        public static Point[] testStruct1()
        {
            Point[] array = new Point[]
            {
                new Point{x=1,y=2},
                new Point{x=2,y=1},
            };
            array[0].x = 3;
            return array;
        }
        public static Point[] testStruct2()
        {
            Point[] array = new Point[]
            {
                new Point{x=1,y=2},
                new Point{x=2,y=1},
            };
            array[0] = Point.SAdd(array[0], array[1]);
            return array;
        }
        public static string testTons2()
        {
            char[] a = { 'a', 'b', 'c' };
            //string c = "";
            //for(var i=0;i<a.Length;i++)
            //{
            //    c += a[i];
            //}
            return "c";
        }
        public static Point[] testStruct3()
        {
            Point a = new Point { x = 1, y = 2 };
            Point b = a;
            b.x = 3;
            Point[] array = new Point[] { a, b };
            return array;
        }
        public static int testzhitong(int a)
        {
            System.Diagnostics.Debugger.Break();
            Storage.Put(Storage.CurrentContext, "h", "e");
            return a;
        }

        public static int testArray()
        {
            int[] abc = new int[] { 0, 2, 3 };
            abc[0] = 123;
            abc[1] = 445;
            var i = abc.Length;
            var i2 = abc[1];
            return i;
        }

        public static int testStringArray()
        {
            string[] abc = new string[3] { "bbb", "ccc", "aaa" };
            abc[0] = "123";
            abc[1] = "445";
            var i = abc.Length;
            var i2 = abc[1];
            return i;
        }
        public static int[] testValueClone()
        {
            int i = 0;
            int b = 0;
            i = b;
            b = 4;
            return new int[] { i, b };
        }
        public static object testCharArray()
        {
            //char[] abc = { '0', '1', '2' };
            string a = "abcdef";
            char c = a[2];
            return c;
        }
        public static byte[] tMain()
        {
            var hexStr = "027b30";
            byte[] pubKey = HexToBytes(hexStr);
            return pubKey;
        }

        private static byte[] HexToBytes(string value)
        {
            string ss = "";
            //byte[] returnBytes = new byte[value.Length / 2];
            for (int i = 0; i < value.Length / 2; i++)
                ss += (char)(ToByte(value[i * 2]) << 4 | ToByte(value[i * 2 + 1]));
            return ss.AsByteArray();
        }

        private static int ToByte(char c)
        {
            var hex = "0123456789abcdef";
            for (int i = 0; i < hex.Length; i++)
            {
                if (c == hex[i])
                    return i;
            }
            return -1;
        }
        private static BigInteger BytesToInt(byte[] array)
        {
            return new BigInteger(array);
        }

    }
}
